﻿using System;
using System.Collections.Generic; 
using System.Text;
using System.IO;


public class Crypto
{
    #region Encrypt Message

    public static string EncryptStringAES(string plainMessage)
    {
        string strmsg = string.Empty;
        try
        {
            byte[] encode = new byte[plainMessage.Length];
            encode = Encoding.UTF8.GetBytes(plainMessage);
            strmsg = Convert.ToBase64String(encode);
        }
        catch (Exception ex)
        {
        }
        return strmsg;
    }

    #endregion

    #region Decrypt Message

    public static string DecryptStringAES(string EncryptMessage)
    {
        string decryptpwd = string.Empty;
        try
        {
            UTF8Encoding encodepwd = new UTF8Encoding();
            Decoder Decode = encodepwd.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(EncryptMessage);
            int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            char[] decoded_char = new char[charCount];
            Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            decryptpwd = new String(decoded_char);
        }
        catch (Exception ex)
        {

        }
        return decryptpwd;
    }

    #endregion
}
 
